<template>
  <view class="map_container">
    <map style="width: 100%; height: 100%;" enable-3D="false" show-compass="false"
      enable-overlooking="false" :enable-satellite="false" :enable-traffic="false"
      show-location="false" :latitude="latitude" :longitude="longitude" :markers="covers">
    </map>
  </view>
</template>

<script>
  export default {
    name: 'MapEle',
    data() {
      return {
        covers: [],
        latitude: '',
        longitude: '',
        query: {}
      }
    },
    onShow() {
      this.getLocaltion()
    },
    methods: {
      getLocaltion() {
        uni.chooseLocation( {
          success: res => {
            console.log( '位置名称：' + res.name );
            console.log( '详细地址：' + res.address );
            console.log( '纬度：' + res.latitude );
            console.log( '经度：' + res.longitude );
            uni.getLocation( {
              type: 'gcj02',
              altitude: true,
              geocode: true,
              success: function ( res ) {
                console.log( '当前位置的经度：' + res.longitude );
                console.log( '当前位置的纬度：' + res.latitude );
              }
            } );
            console.log( '省：' + res.address.slice( 0, res.address.indexOf(
              '省' ) + 1 ) );
            console.log( '市：' + res.address.slice( res.address.indexOf( '省' ) +
              1, res.address.indexOf( '市' ) + 1 ) );
            console.log( '区：' + res.address.slice( res.address.indexOf( '市' ) +
              1, res.address.indexOf( '区' ) + 1 ) );
            this.query.address = res.address;
            this.query.latitude = res.latitude;
            this.query.longitude = res.longitude;
            this.query.province = res.address.slice( 0, res.address.indexOf(
              '省' ) + 1 )
            this.query.city = res.address.slice( res.address.indexOf( '省' ) + 1,
              res.address.indexOf( '市' ) + 1 )
            this.query.district = res.address.slice( res.address.indexOf(
              '市' ) + 1, res.address.indexOf( '区' ) + 1 )
          },
          fail( err ) {
            console.log( err );
          }
        } );
      }
    }
  }
</script>

<style>
</style>